<?php
/**
 * Test handler for WikkaAction class and PhpMailer
 *
 * Provides basic output to test command line version (cli.php) of wikka.
 *
 * Usage:
 *      php cli.php -c CONFIG_KEY cli/test_gmail
 *
 * @package		Handlers
 * @subpackage	        Page
 * @version		$Id$
 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
 * @filesource
 */

require_once 'libs/action.class.php';

class GmailTestHandler extends WikkaAction {

    function getToList() {
        $list = array(
            array($this->Wikka->GetConfigValue('gmail_user'), 'mailer'),
            array($this->Wikka->GetConfigValue('admin_email'), 'admin')
        );
        return $list;
    }

    function send_single_email() {
        $email = $this->Wikka->GetConfigValue('admin_email');
        $subject = 'wikka phpmailer test: single email';
        $body = sprintf('mail sent to: %s', $email);
        if ( $this->mail($email, $subject, $body) ) {
            printf("%s: OK\n", __FUNCTION__);
        }
        else {
            printf("%s: FAIL\n", __FUNCTION__);
        }
    }

    function send_email_list() {
        $subject = 'wikka phpmailer test: email list';
        $body = sprintf('mail sent to: %s', print_r($this->getToList(),1));
        if ( $this->mail($this->getToList(), $subject, $body) ) {
            printf("%s: OK\n", __FUNCTION__);
        }
        else {
            printf("%s: FAIL\n", __FUNCTION__);
        }
    }
}

# Main Routine
try {
    $Handler = new GmailTestHandler($this);
    $Handler->send_single_email();
    $Handler->send_email_list();
    print "script complete\n";
}
catch(Exception $e) {
    print $e->getMessage();
}
?>
